package com.xpffly.design.iterator.demo.service.impl;

import com.xpffly.design.iterator.demo.service.IProject;
import com.xpffly.design.iterator.demo.service.IProjectIterator;

import java.util.ArrayList;

/**
 * @Author: xpengfei
 * @Date: 2021/4/13 23:31
 * @Description：项目信息
 */
public class Project implements IProject {
    /**
     * 定义一个项目list，存放所有的项目信息
     */
    private ArrayList<IProject> projectArrayList = new ArrayList<IProject>();
    /**
     * 项目名称
     */
    private String name = "";
    /**
     * 项目成员数量
     */
    private int num = 0;
    /**
     * 项目费用
     */
    private int cost = 0;

    public Project() {
    }

    public Project(String name, int num, int cost) {
        this.name = name;
        this.num = num;
        this.cost = cost;
    }

    /**
     * 增加项目
     *
     * @param name 项目名称
     * @param num  项目人数
     * @param cost 项目费用
     */
    public void addProject(String name, int num, int cost) {
        this.projectArrayList.add(new Project(name, num, cost));
    }

    /**
     * 获取项目信息
     *
     * @return
     */
    public String getProjectInfo() {
        String info = "";
        info += "项目名称：" + this.name;
        info += "\t项目人数：" + this.num;
        info += "\t项目费用为：" + this.cost;
        return info;
    }

    /**
     * 获取一个可以遍历的对象
     *
     * @return
     */
    public IProjectIterator iterator() {
        return new ProjectIterator(this.projectArrayList);
    }

}
